{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/tmp\n"
     ]
    }
   ],
   "source": [
    "cd /tmp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from finta import TA\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "ohlc = pd.read_csv(\"HistoricalQuotes.csv\", index_col=\"Date\", parse_dates=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "ohlc.columns = ['close', 'volume', 'open', 'high', 'low']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def split(dollar: str) -> float:\n",
    "    return float(dollar.split(\"$\")[1])\n",
    "\n",
    "ohlc[\"close\"] = ohlc[\"close\"].apply(split)\n",
    "\n",
    "ohlc[\"low\"] = ohlc[\"low\"].apply(split)\n",
    "\n",
    "ohlc[\"high\"] = ohlc[\"high\"].apply(split)\n",
    "\n",
    "ohlc[\"open\"] = ohlc[\"open\"].apply(split)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Date\n",
       "2014-12-26    55.099394\n",
       "2014-12-24    43.666451\n",
       "2014-12-23    50.085415\n",
       "2014-12-22    50.594291\n",
       "2014-12-19    38.730709\n",
       "2014-12-18    35.584319\n",
       "2014-12-17    38.632773\n",
       "2014-12-16    32.701255\n",
       "2014-12-15    55.449033\n",
       "2014-12-12    57.338081\n",
       "Name: RSI, dtype: float64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "TA.RSI(ohlc).tail(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "from finta.utils import resample_calendar\n",
    "weekly_ohlc = resample_calendar(ohlc, \"7d\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Date\n",
       "2019-10-04    1756.299843\n",
       "2019-10-11    1766.693228\n",
       "2019-10-18    1771.388819\n",
       "2019-10-25    1773.145879\n",
       "2019-11-01    1778.163920\n",
       "2019-11-08    1770.309280\n",
       "2019-11-15    1758.442853\n",
       "2019-11-22    1778.465235\n",
       "2019-11-29    1765.803490\n",
       "2019-12-06    1760.108994\n",
       "Freq: W-FRI, Name: 5 period EMA, dtype: float64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "TA.EMA(weekly_ohlc, 5).tail(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
